perm filename PROBS1.XGP[206,LSP] blob
sn#347720 filedate 1978-04-12 generic text, type T, neo UTF8
/LMAR=0/XLINE=3/FONT#0=BAXL30[FNT,CLT]/FONT#1=BAXM30/FONT#2=BAXB30[FNT,CLT]/FONT#5=NGR25/FONT#3=SUB/FONT#4=SUP/FONT#7=SYMB30[FNT,CLT]
␈↓ ↓H␈↓␈↓ ¬πSTANFORD UNIVERSITY
␈↓ ↓H␈↓CS206 ␈↓ βZCOMPUTING WITH SYMBOLIC EXPRESSIONS ␈↓
0FALL 1977
␈↓ ↓H␈↓␈↓ ¬DPROBLEM SET 1
␈↓ ↓H␈↓␈↓ ¬[Due October 11
␈↓ ↓H␈↓αGeneral homework policy.
␈↓ ↓H␈↓ When␈αthe␈αhomework␈αinvolves␈αwriting␈αLISP␈αfunctions,␈αdebug␈αyour␈αfunctions␈αusing␈αLISP␈αat
␈↓ ↓H␈↓LOTS. Prepare a file that contains for each function the following:
␈↓ ↓H␈↓ 1) The external form of your function.
␈↓ ↓H␈↓ 2) A ␈↓↓brief␈↓ description of how it works and why.
␈↓ ↓H␈↓ 3) An internal form listing.
␈↓ ↓H␈↓ 4) Results from some representative sample runs.
␈↓ ↓H␈↓List␈α∂this␈α∂file␈α∂and␈α∂turn␈α∂it␈α∞in.␈α∂ Include␈α∂also␈α∂the␈α∂name␈α∂of␈α∞the␈α∂file␈α∂where␈α∂the␈α∂functions␈α∂live.␈α∞ (For
␈↓ ↓H␈↓grading␈αpurposes,␈αin␈αcase␈αsomething␈αis␈αnot␈αclear,␈αit␈αis␈αuseful␈αto␈αtry␈αout␈αa␈αfunction␈αon␈αsuitable␈αtest
␈↓ ↓H␈↓cases.)
␈↓ ↓H␈↓ Solutions␈α
will␈α
be␈α
put␈α
up␈α
in␈α
a␈α
file␈α
on␈αthe␈α
<CS206>␈α
directory␈α
and␈α
you␈α
will␈α
be␈α
able␈α
to␈αlist,␈α
read,
␈↓ ↓H␈↓or␈α⊃load␈α⊂and␈α⊃try␈α⊂them.␈α⊃ Late␈α⊂assignments␈α⊃are␈α⊂discouraged␈α⊃and␈α⊂will␈α⊃not␈α⊂be␈α⊃accepted␈α⊃after␈α⊂the
␈↓ ↓H␈↓solutions appear.
␈↓ ↓H␈↓αAssignment.
␈↓ ↓H␈↓ Write the following LISP functions.
␈↓ ↓H␈↓1.␈α␈↓↓foo␈αu␈↓␈α is␈αa␈αlist␈αconsisting␈αof␈αthe␈αatomic␈αelements␈αof␈αthe␈αlist␈α␈↓↓u␈↓␈αfollowed␈αby␈αa␈αlist␈αof␈αthe␈αnonatomic
␈↓ ↓H␈↓␈↓ α(elements of ␈↓↓u␈↓ preserving the order within each group. Thus
␈↓ ↓H␈↓␈↓ ∧1␈↓↓foo[␈↓¬(A (B C) A B (D E))␈↓↓] = ␈↓¬(A A B (B C) (D E))␈↓↓␈↓
␈↓ ↓H␈↓2.␈α
␈↓↓prod[u,␈α
v]␈↓␈α
is␈α
the␈α∞product␈α
of␈α
the␈α
polynomials␈α
␈↓↓u␈↓␈α
and␈α∞␈↓↓v.␈↓␈α
We␈α
consider␈α
only␈α
polynomials␈α∞in␈α
one
␈↓ ↓H␈↓␈↓ α(variable,␈α∪say␈α∪␈↓↓x,␈↓␈α∩and␈α∪represent␈α∪a␈α∪polynomial␈α∩as␈α∪a␈α∪list␈α∪of␈α∩its␈α∪coefficients␈α∪in␈α∪order␈α∩of
␈↓ ↓H␈↓␈↓ α(increasing powers of ␈↓↓x.␈↓ Thus ␈↓↓x␈↓∧3␈↓↓+x+5␈↓ is represented by ␈↓¬(5 1 0 1)␈↓.
␈↓ ↓H␈↓3.␈α␈↓↓locations[e,␈αu]␈↓␈αis␈αa␈αlist␈αof␈αthe␈αlocations␈αwhere␈α␈↓↓e␈↓␈αoccurs␈αas␈αa␈αsubexpression␈αof␈α␈↓↓u.␈↓␈α A␈αlocation␈αis␈αa
␈↓ ↓H␈↓␈↓ α(list␈α∂␈↓↓l␈↓=(β␈↓β1␈↓ ... β␈↓βn␈↓)␈α∂where␈α∂each␈α∂β␈↓βi␈↓␈α∂is␈α∂␈↓¬A␈α∂␈↓or␈α∂␈↓¬D␈α∂␈↓and␈α∂␈↓¬(Cβ␈↓β1␈↓¬R ... (Cβ␈↓βn␈↓¬R ␈↓↓u␈↓¬)...)␈↓␈α∂is␈α∂the␈α∂subexpression␈α∂at
␈↓ ↓H␈↓␈↓ α(location ␈↓↓l␈↓ in ␈↓↓u.␈↓ Thus
␈↓ ↓H␈↓␈↓ ∧N␈↓↓locations[␈↓¬Y, ␈↓↓␈↓¬(((X . Y) . Z) . X)␈↓↓] = ␈↓¬((D A A))␈↓↓␈↓
␈↓ ↓H␈↓4.␈α␈↓↓commons␈αx␈↓␈αis␈αa␈αlist␈αof␈αpairs.␈α The␈αset␈αof␈α␈↓↓car␈↓'s␈αof␈αthe␈αpairs␈αis␈αthe␈αset␈αof␈αsubexpressions␈αof␈αthe␈αS-
␈↓ ↓H␈↓␈↓ α(expression␈α∂␈↓↓x␈↓␈α∂that␈α⊂occur␈α∂more␈α∂than␈α⊂once␈α∂in␈α∂␈↓↓x␈↓␈α⊂and␈α∂the␈α∂␈↓↓cdr␈↓␈α⊂of␈α∂each␈α∂pair␈α⊂is␈α∂a␈α∂list␈α⊂of␈α∂the
␈↓ ↓H␈↓␈↓ α(locations where the ␈↓↓car␈↓ occurs. Thus
␈↓ ↓H␈↓␈↓ ∧%␈↓↓commons ␈↓¬(((X . Y) . Z) . X)␈↓↓ = ␈↓¬((X . ((A A A) (D))))␈↓↓␈↓